package com.javasm.controller;


import com.javasm.common.http.AxiosResult;
import com.javasm.common.page.PageResult;
import com.javasm.controller.base.BaseController;
import com.javasm.domin.criteria.AftersaleB2cRetreatCriteria;
import com.javasm.domin.entity.AftersaleB2cChange;
import com.javasm.domin.vo.AftersaleB2cChangeVo;
import com.javasm.service.AftersaleB2cChangeService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author whl
 * @since 2022-01-13
 */
@RestController
@RequestMapping("aChange")
@RequiredArgsConstructor//和@Autowired效果一样
public class AftersaleB2cChangeController extends BaseController {

    public final AftersaleB2cChangeService aftersaleB2cChangeService;

    /**
     * 添加
     * @param aftersaleOut
     * @return
     */
    @PostMapping
    public AxiosResult<Void> add (@RequestBody AftersaleB2cChange aftersaleB2cChange){
        LocalDateTime sj = LocalDateTime.now();
        aftersaleB2cChange.setEstablishTime(sj);
        return toAxios(aftersaleB2cChangeService.save(aftersaleB2cChange));
    }

    /**
     * 制单修改
     * @param aftersaleOut
     * @return
     */
    @PutMapping
    public AxiosResult<Void> update (@RequestBody AftersaleB2cChange aftersaleB2cChange){
        LocalDateTime sj = LocalDateTime.now();
        aftersaleB2cChange.setEstablishTime(sj);
        return toAxios(aftersaleB2cChangeService.update(aftersaleB2cChange));
    }

    /**
     * 审批修改
     * @param aftersaleOut
     * @return
     */
    @PutMapping("sp")
    public AxiosResult<Void> updatesp (@RequestBody AftersaleB2cChange aftersaleB2cChange){
        LocalDateTime sj = LocalDateTime.now();
        aftersaleB2cChange.setConfirmTime(sj);
        return toAxios(aftersaleB2cChangeService.update(aftersaleB2cChange));
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping("{id}")
    public AxiosResult<Void> delete (@PathVariable Long id){
        return toAxios(aftersaleB2cChangeService.deleteById(id));
    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @GetMapping("{id}")
    public AxiosResult<AftersaleB2cChange> findById(@PathVariable Long id){
        AftersaleB2cChange byId = aftersaleB2cChangeService.getById(id);
        return AxiosResult.success(byId);
    }


    /**
     * 分页条件查询
     */
    @GetMapping
    public AxiosResult<PageResult<AftersaleB2cChangeVo>> list(AftersaleB2cRetreatCriteria aftersaleB2cRetreatCriteria){
        //分页条件查询
        return AxiosResult.success(aftersaleB2cChangeService.searchPage(aftersaleB2cRetreatCriteria));

    }
    /**
     * 批量删除
     */

    @DeleteMapping("batch/{ids}")
    public AxiosResult<Void> batchDelete(@PathVariable List<Long> ids){
        return toAxios(aftersaleB2cChangeService.batchDeleteByIds(ids));
    }

}
